package cn.iocoder.yudao.module.member.controller.app.pickupinfo;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.member.controller.app.pickupinfo.vo.PickupInfoRespVO;
import cn.iocoder.yudao.module.member.controller.app.pickupinfo.vo.PickupInfoSaveReqVO;
import cn.iocoder.yudao.module.member.convert.pickupinfo.PickUpInfoConvert;
import cn.iocoder.yudao.module.member.dal.dataobject.pickupinfo.PickupInfoDO;
import cn.iocoder.yudao.module.member.service.pickupinfo.PickupInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

@Tag(name = "管理后台 - 用户提料人信息")
@RestController
@RequestMapping("/member/pickup-info")
@Validated
public class AppPickupInfoController {

    @Resource
    private PickupInfoService pickupInfoService;

    @PostMapping("/create")
    @Operation(summary = "创建用户提料人信息")
    public CommonResult<Long> createPickupInfo(@Valid @RequestBody PickupInfoSaveReqVO createReqVO) {
        return success(pickupInfoService.createPickupInfo(getLoginUserId(), createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新用户提料人信息")
    public CommonResult<Boolean> updatePickupInfo(@Valid @RequestBody PickupInfoSaveReqVO updateReqVO) {
        pickupInfoService.updatePickupInfo(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除用户提料人信息")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deletePickupInfo(@RequestParam("id") Long id) {
        pickupInfoService.deletePickupInfo(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得用户提料人信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<PickupInfoRespVO> getPickupInfo(@RequestParam("id") Long id) {
        PickupInfoDO pickupInfo = pickupInfoService.getPickupInfo(id);
        return success(PickUpInfoConvert.INSTANCE.convert(pickupInfo));
    }

    @GetMapping("/get-default")
    @Operation(summary = "获得默认的提料人信息")
    public CommonResult<PickupInfoRespVO> getDefaultUserAddress() {
        PickupInfoDO pickupInfo = pickupInfoService.getDefaultPickupInfo(getLoginUserId());
        return success(PickUpInfoConvert.INSTANCE.convert(pickupInfo));
    }

    @GetMapping("/list")
    @Operation(summary = "获得提料人信息列表")
    public CommonResult<List<PickupInfoRespVO>> getAddressList() {
        List<PickupInfoDO> list = pickupInfoService.getPickupInfoList(getLoginUserId());
        return success(PickUpInfoConvert.INSTANCE.convert(list));
    }

}